#include "CXInput.h"

CXInput CXInput::m_Instance;

CXInput* CXInput::GetInstance(void)
{
	return &m_Instance;
}

CXInput::CXInput(void)
{
	ControllerNum = 0;

	m_bIsADown = false;	
	m_bIsBDown = false;
	m_bIsXDown = false;
	m_bIsYDown = false;
	m_bIsStartDown = false;
	m_bIsBackDown = false;
	m_bIsRBDown = false;
	m_bIsLBDown = false;
	m_bIsRTDown = false;
	m_bIsLTDown = false;
	m_bIsUpDown = false;
	m_bIsLeftDown = false;
	m_bIsRightDown = false;
	m_bIsDownDown = false;
	m_bIsLStickMoved = false;
	m_bIsRStickMoved = false;
}

CXInput::~CXInput(void)
{

}

XINPUT_STATE CXInput::GetState()
{
	ZeroMemory(&ControllerState, sizeof(XINPUT_STATE));

	XInputGetState(ControllerNum, &ControllerState);

	return ControllerState;
}
bool CXInput::IsConnected()
{
	ZeroMemory(&ControllerState, sizeof(XINPUT_STATE));

	DWORD Result = XInputGetState(ControllerNum, &ControllerState);

	if(Result == ERROR_SUCCESS)
	{
		return true;
	}
	else
	{
		return false;
	}
}
void CXInput::Vibrate(int leftVal, int rightVal)
{
	XINPUT_VIBRATION Vibration;

	ZeroMemory(&Vibration, sizeof(XINPUT_VIBRATION));

	Vibration.wLeftMotorSpeed = leftVal;
	Vibration.wRightMotorSpeed = rightVal;

	XInputSetState(ControllerNum, &Vibration);
}
DWORD CXInput::PressButton()
{
	return GetState().Gamepad.wButtons;
}
BYTE CXInput::PullLTrigger()
{
	return GetState().Gamepad.bLeftTrigger;
}
BYTE CXInput::PullRTrigger()
{
	return GetState().Gamepad.bRightTrigger;
}
SHORT CXInput::LStickY()
{
	return GetState().Gamepad.sThumbLY;
}
SHORT CXInput::LStickX()
{
	return GetState().Gamepad.sThumbLX;
}
SHORT CXInput::RStickY()
{
	return GetState().Gamepad.sThumbRY;
}
SHORT CXInput::RStickX()
{
	return GetState().Gamepad.sThumbRX;
}